<template>
	<view class="ask-index">
		<scroll-view style="height: 100vh" scroll-y="true" @scrolltolower="loadmore">
			<view class="ask-title">
				常见问题
			</view>

			<view class="list-list" v-if="list && list.length>0">
				<view class="list-item" v-for="(item ,index) in list" :key="index">
					<view class="icon">
						<image src="../../static/image/ask.png"></image>
					</view>
					<view class="item-right">
						<view class="name">{{item.question}} </view>
						<view class="des">{{item.answer}} </view>
					</view>
				</view>
			</view>
			<u-loadmore :status="status" />
		</scroll-view>
	</view>

</template>

<script>
	import {getQuestion} from '@/api/public.js'
	export default {
		components: {

		},
		data() {
			return {
				status: 'loadmore',
				list: [],
				params: {
					pageNum: 1,
					pageSize: 10
				},
				total: 0,
			}
		},
		onLoad() {

		},
		created() {},
		onShow() {
			this.list = []
			this.getList()

		},
		methods: {
			loadmore() {
				if (this.list.length >= this.total) {
					this.status = 'nomore'
					return
				}
				this.params.pageNum = this.params.pageNum + 1
				this.getList()
			},

			getList() {
				this.status = 'loading';
				uni.showLoading({
					title: '加载中'
				})
				getQuestion(this.params).then(res => {
					const {
						total,
						rows
					} = res
					if (rows && rows.length > 0) {
						this.list = [...this.list, ...rows]
					}
					this.total = total
					if (total === 0) {
						this.status = 'nomore'
						return
					}
					if (this.list.length >= this.total) {
						this.status = 'nomore'
						return
					}
				}).finally(() => {
					uni.hideLoading()
				})
			}

		}

	}
</script>

<style lang="scss" scoped>
	.clearfix {
		clear: both;
	}

	.ask-index {
		background: #F0F2F5;
		width: 100vw;
		min-height: 100vh;

		.ask-title {
			height: 59rpx;
			font-size: 42rpx;
			font-ask: 600;
			color: #323232;
			line-height: 59rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			padding-top: 30rpx;

		}

		.list-list {
			width: 690rpx;
			margin: 50rpx auto;

			.list-item {
				background: #F5F7FA;
				border-radius: 1rpx;
				margin-bottom: 20rpx;
				display: flex;
				padding: 25rpx 20rpx;

				.icon {
					margin-right: 20rpx;
					width: 40rpx;

					image {
						width: 40rpx;
						height: 40rpx;
					}
				}

				.item-right {
					.name {
						font-size: 28rpx;
						font-weight: 400;
						color: #323232;
						margin-bottom: 18rpx;
					}

					.des {
						font-size: 28rpx;
						font-weight: 400;
						color: #909399;
					}
				}
			}


		}
	}
</style>
